﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Dapper.Common;

namespace DapperExtensions
{
    public class DapperBaseService<T> : IDapperBaseService<T>
    {
        private IRepository<T> _repository;

        public DapperBaseService(IRepository<T> repository)
        {
            _repository = repository;
        }

        public void Delete(T obj)
        {
            _repository.Delete(obj);
        }

        public int Execute(string sql, object param = null, CommandType commandType = CommandType.Text, int? commandTimeout = null)
        {
            return _repository.Execute(sql, param, commandType, commandTimeout);
        }

        public T Get(long id)
        {
            return _repository.Get(id);
        }

        public IList<T> GetAll()
        {
            return _repository.GetAll();
        }

        public IEnumerable<T> GetList(object predicate, IList<ISort> sort = null, int? commandTimeout = null, bool buffered = false)
        {
            return _repository.GetList(predicate, sort, commandTimeout, buffered);
        }

        public PagedResultOutput<T> GetPage(object predicate, IList<ISort> sort = null, int pageIndex = 1, int pageSize = 20, int? commandTimeout = null, bool buffered = false)
        {
            return _repository.GetPage(predicate, sort, pageIndex, pageSize, commandTimeout, buffered);
        }

        public void Insert(T obj)
        {
            _repository.Insert(obj);
        }

        public void Update(T obj)
        {
            _repository.Update(obj);
        }
    }
}